<template>
  <div class="row">
    <div class="col-3 d-flex align-items-center justify-content-center">
      <img :src="fitUrl" alt="jpg">
    </div>
    <div class="col d-flex flex-column justify-content-center" v-if="user">
      <h4>{{user.nickName}}</h4>
      <div class="text-muted">{{user.description}}</div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { userProps } from '../store'
import { addColumnAvatar } from '../helps'

// 图片格式处理方法
const imageFunc = (props: any) => {
  const fitUrl = computed(() => {
    addColumnAvatar(props.user, 50, 50)
    const { avatar } = props.user
    return avatar && avatar.fitUrl
  })
  return { fitUrl }
}

export default defineComponent({
  name: 'UserProfile',
  props: {
    user: {
      type: Object as PropType<userProps>,
      required: true
    }
  },
  setup (props) {
    const { fitUrl } = imageFunc(props)
    return {
      fitUrl
    }
  }
})
</script>
